package cn.shutdown.redis;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;

/**
 * 通过Factory创建JedisCluster
 * @author jiangwujie
 * @date 2021/11/8
 */
public class JedisDemo4 {

    public static void main(String[] args) throws Exception {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                "classpath:applicationContext4.xml");

        long dbcount = 0;
        //slots:3001-6000
        Jedis jedis = new Jedis("10.4.7.222", 7002);
        for (int i = 0; i < 16384; i++) {
            long count = jedis.clusterCountKeysInSlot(i);
            dbcount += count;
            if (i > 6000 || i < 3001) {
                if (count > 0) {
                    System.out.println("10.4.7.222:" + 7002 + " slot:" + i + " keyCount:" + count);
                }
            }
        }
        System.out.println("10.4.7.222:" + 7002 + " dbsize:" + dbcount);
        jedis.close();


        dbcount = 0;
        //slots:10001-16383
        jedis = new Jedis("10.4.7.221", 8013);
        for (int i = 0; i < 16384; i++) {
            long count = jedis.clusterCountKeysInSlot(i);
            dbcount += count;
            if (i > 16383 || i < 10001) {
                if (count > 0) {
                    System.out.println("10.4.7.221:" + 8013 + " slot:" + i + " keyCount:" + count);
                }
            }
        }
        System.out.println("10.4.7.221:" + 8013 + " dbsize:" + dbcount);
        jedis.close();


        dbcount = 0;
        //slots:0-3000
        jedis = new Jedis("10.4.7.221", 7001);
        for (int i = 0; i < 16384; i++) {
            long count = jedis.clusterCountKeysInSlot(i);
            dbcount += count;
            if (i > 3000 || i < 0) {
                if (count > 0) {
                    System.out.println("10.4.7.221:" + 7001 + "slot:" + i + " keyCount:" + count);
                }
            }
        }
        System.out.println("10.4.7.221:" + 7001 + " dbsize:" + dbcount);
        jedis.close();


        dbcount = 0;
        //slots:6001-9000
        jedis = new Jedis("10.4.7.221", 7013);
        for (int i = 0; i < 16384; i++) {
            long count = jedis.clusterCountKeysInSlot(i);
            dbcount += count;
            if (i > 9000 || i < 6001) {
                if (count > 0) {
                    System.out.println("10.4.7.221" + 7013 + "slot:" + i + " keyCount:" + count);
                }
            }
        }
        System.out.println("10.4.7.221:" + 7013 + " dbsize:" + dbcount);
        jedis.close();


        dbcount = 0;
        //slots:9001-10000
        jedis = new Jedis("10.4.7.221", 7004);
        for (int i = 0; i < 16384; i++) {
            long count = jedis.clusterCountKeysInSlot(i);
            dbcount += count;
            if (i > 10000 || i < 9001) {
                if (count > 0) {
                    System.out.println("10.4.7.221:" + 7004 + " slot:" + i + " keyCount:" + count);
                }
            }
        }
        System.out.println("10.4.7.221:" + 7004 + " dbsize:" + dbcount);
        jedis.close();
    }
}
